#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
GTest 夹具测试用例
"""

from gtest import test_f, fixture, EXPECT_EQ, EXPECT_TRUE, EXPECT_FALSE
from mc.types import int32_t


@fixture()
class MathFixture:
    """数学运算测试夹具"""

    def __init__(self):
        self.base_value: int32_t = 10
        self.multiplier: int32_t = 2
        self.offset: int32_t = 5

    def calculate_result(self, input_value: int32_t) -> int32_t:
        """计算结果的辅助方法"""
        return (input_value + self.offset) * self.multiplier

    def is_even(self, value: int32_t) -> bool:
        """检查数字是否为偶数"""
        return value % 2 == 0


@test_f("MathFixture", "CalculateWithPositive")
def test_calculate_positive(self: MathFixture):
    """测试正数计算"""
    input_val: int32_t = 3
    result: int32_t = self.calculate_result(input_val)
    expected: int32_t = (3 + 5) * 2  # (3 + 5) * 2 = 16
    EXPECT_EQ(result, expected)


@test_f("MathFixture", "CalculateWithZero")
def test_calculate_zero(self: MathFixture):
    """测试零值计算"""
    input_val: int32_t = 0
    result: int32_t = self.calculate_result(input_val)
    expected: int32_t = (0 + 5) * 2  # (0 + 5) * 2 = 10
    EXPECT_EQ(result, expected)


@test_f("MathFixture", "CalculateWithNegative")
def test_calculate_negative(self: MathFixture):
    """测试负数计算"""
    input_val: int32_t = -3
    result: int32_t = self.calculate_result(input_val)
    expected: int32_t = (-3 + 5) * 2  # (-3 + 5) * 2 = 4
    EXPECT_EQ(result, expected)


@test_f("MathFixture", "EvenNumberCheck")
def test_even_check(self: MathFixture):
    """测试偶数检查"""
    EXPECT_TRUE(self.is_even(4))
    EXPECT_TRUE(self.is_even(0))
    EXPECT_FALSE(self.is_even(3))
    EXPECT_FALSE(self.is_even(7))


@test_f("MathFixture", "BaseValueOperations")
def test_base_value_ops(self: MathFixture):
    """测试基础值操作"""
    doubled: int32_t = self.base_value * 2
    EXPECT_EQ(doubled, 20)

    with_offset: int32_t = self.base_value + self.offset
    EXPECT_EQ(with_offset, 15)

    EXPECT_TRUE(self.is_even(self.base_value))
